package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName EduTeacherFrontController
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/6/24
 * @Version 1.0
 */
@RestController
@RequestMapping("/eduservice/teacherfront")
//@CrossOrigin
public class EduTeacherFrontController {

    @Autowired
    EduTeacherService eduTeacherService;

    @Autowired
    EduCourseService eduCourseService;

    @GetMapping("/getTeacherFrontList/{page}/{size}")
    public R getTeacherFrontList(@PathVariable("page") int page,@PathVariable("size") int size){
        Page<EduTeacher> teacherPage=new Page<>(page,size);
        //需要返回多个参数可以使用map集合进行封装
        Map<String,Object> map=eduTeacherService.getTeacherFrontList(teacherPage);
        //使用map封装不需要指定key
        return R.ok().data(map);
    }

    @GetMapping("getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable("id") String id){
        EduTeacher eduTeacher = eduTeacherService.getById(id);
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> eduCourseList = eduCourseService.list(wrapper);
        return R.ok().data("teacher",eduTeacher).data("courseList",eduCourseList);
    }

}
